Skip to content

Adapt updated_since page selection to recent-result size - #1865

Draft
rdimitrov wants to merge 4 commits into
mainfrom
codex/bounded-updated-page-query
Draft

rdimitrov wants to merge 4 commits into
mainfrom
codex/bounded-updated-page-query

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Incremental listing queries can scan a large name range for sparse results or sort too much recent history for an early page. This change selects page keys first and fetches payloads only for that page. Plain updated_since&limit=100 requests probe up to 513 matching keys in timestamp order: a complete set of at most 512 keys is sorted into public name/version order; larger sets use the name-ordered path. Other incremental shapes retain the 128-match boundary.

For larger histories, bounded per-app strategy hints avoid repeating a probe that is likely to be discarded. One in 16 eligible requests can observe the probe result; up to 32 timestamp/name ranges are retained for five seconds, separately for deletion filtering. Hints contain no response rows. Every request still applies the complete predicate in one statement snapshot, so concurrent writes or stale hints can affect plan efficiency but cannot make results stale or omit matching rows. Transaction-owned reads and additional filters bypass hints. PostgreSQL checks cursor coverage behind a materialized guard, preserving generic-plan reuse. Sampled queries return one internal marker row, excluded from API results, pagination and row metrics.

SQL is constructed explicitly in named helpers; there are no prototype string replacements. Plain incremental page sizes 1 and 100 reuse prepared statements with the validated limit embedded and all request values bound. Other sizes/filters retain parameter-specific planning. No global planner, replica or connection-limit changes.

Migration 020 replaces the listing indexes with (server_name, version, updated_at) INCLUDE (is_latest, status) and (updated_at DESC, server_name, version). It validates replacements before dropping old indexes transactionally. The deployment guide requires concurrent prebuilds on busy databases and documents recovery/application rollback.

Validation for 5dbdbe8:

  • Full PostgreSQL database suite, native Go race checks for incremental listing, lint and Linux AMD64 application build passed locally.
  • Tests cover probe boundaries, changing watermarks/cursors, stale hints after writes/deletes, expiry/eviction, concurrent access, deletion-filter and transaction isolation, legacy name-only cursors, bound parameters, marker exclusion/schema invariant and actual generic-plan reuse.
  • 1,008 paired API responses matched the 512-only control across twelve history changes up to 50,000 extra recent rows, without clearing pools/hints. Both API versions, filters, limits 1/10/100 and a 35-row limit=1 pagination walk matched.
  • Six controlled local quiet → burst → recovery cycles used six fixed apps, max20/min5 connections per app and PostgreSQL17.5 at 3 CPU/4GiB. Each cycle ran 30s at 150 reads/s, 60s at 1,500 reads/s plus 10 publishes/s, then 30s recovery. All 594,000 reads and 3,960 publishes completed with no dropped reads or HTTP errors, and recovery had zero sampled pool pending.
Initial recent rows 512-only DB CPU Prototype DB CPU Reviewed implementation DB CPU
101 0.526 cores 0.519 cores 0.522 cores
10,101 0.668 cores 0.621 cores 0.618 cores

The reviewed implementation stayed within 0.5% of the prototype in both cases. Small-history CPU stayed in the same range as 512; larger-history CPU was about 7.5% lower. Its worst read-group scheduled p99 was 5.78ms/3.16ms and publish p99 was 6.16ms/4.86ms for small/large history. These are short, local ARM VM measurements, not GKE capacity or latency predictions. Larger-history runs varied watermarks/cursor parameters; comparisons are within each history. Fixture resets used file-copy plus a completed checkpoint; all timed runs verified zero checkpoint writes. Autovacuum was disabled on the disposable fixture to control visibility. No production replay, gateway/cache, network or autoscaling layer was tested.

Keep in draft pending focused staging confirmation of the adaptive implementation. The preceding 512-only build b888b8e improved small-history staging behavior but regressed on larger history with 20 connections per app. This update addresses a measured local contributor; it does not establish that the entire staging regression is resolved or that 1,500 origin requests/s is comfortable on GKE. The probe bounds returned matches, not every index entry visited; stale hints may temporarily choose a slower scan, and the replacement indexes have storage/write costs.

Production and staging were not accessed or changed for this update. Local containers/volume/network were removed and the benchmark VM was stopped with its original configuration restored. Raw data and benchmark evidence remain private.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant